package uml.construct.singleton;

/**
 * 单例--懒汉式<br>
 * 实例的创建将在其首次被使用时被创建，通过双重检查与同步的方式，保证实例唯一性<br>
 * on 2022/12/21 23:33
 */
public class LazySingleton {
    private static volatile LazySingleton instance;

    private LazySingleton() {
    }

    public static LazySingleton getInstance() {
        if (instance == null) {
            synchronized (LazySingleton.class) {
                if (instance == null) {
                    instance = new LazySingleton();
                }
            }
        }
        return instance;
    }
}
